//
//  MaskView+Empty.swift
//  Asman
//
//  Created by 李旭峰 on 7/9/19.
//  Copyright © 2019 李旭峰. All rights reserved.
//

import Foundation
fileprivate var cx_emptyViewKey:Void?
extension UIView {
    fileprivate var emptyMaskView:CXEmptyView?{
        set{
            objc_setAssociatedObject(self, &cx_emptyViewKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
        get{
            return objc_getAssociatedObject(self, &cx_emptyViewKey) as? CXEmptyView
        }
    }
    func cx_showEmpty(){
        if self.emptyMaskView != nil {
            self.emptyMaskView?.removeFromSuperview()
            self.emptyMaskView = nil
        }
        self.emptyMaskView = (Bundle.main.loadNibNamed("CXEmptyView", owner: nil, options: nil)?.first as? CXEmptyView)!
        self.emptyMaskView?.imgEmptyLogo.image = UIImage(named: "img_empty_journals")
        self.emptyMaskView?.isUserInteractionEnabled = false
        self.emptyMaskView?.lbContent.text = "暂无数据"
        self.emptyMaskView?.btnAction.isHidden = true
        self.addSubview(self.emptyMaskView!)
        self.emptyMaskView?.snp.remakeConstraints({ (make) in
            make.centerX.width.equalToSuperview()
            make.top.height.equalToSuperview()
        })
    }
    func cx_removeEmpty(){
        if self.emptyMaskView != nil {
            self.emptyMaskView?.removeFromSuperview()
            self.emptyMaskView = nil
        }
    }
}
